<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Html
 *
 * @author hassanali
 */
$CI = & get_instance();

/**
 * 
 * @global type $CI
 * @param type $type
 * @param type $popupdat
 */
function mobile_popup($type = 'confirm_delete', $popupdat = array()) {
    global $CI;
    if ($type == 'confirm_delete') {
        $popupdate['head'] = 'Delete';
        $popupdate['ok'] = 'Delete';
        $popupdate['cancel'] = 'Cancel';
        $popupdate['div_id'] = 'confirmdelete';
        $popupdate['message'] = 'Are you sure you want to delete this page?';
        foreach ($popupdat as $key => $value) {
            $popupdate[$key] = $value;
        }
        $CI->load->view($CI->themes->Cms_themes() . '/message/confirm_delete', $popupdate);
    }
}

/**
 * 
 * @global type $CI
 * @param type $type
 * @param type $data
 */
function mobile_message($type = 'error', $data) {
    global $CI;
    if ($type == 'error') {
        $CI->load->view($CI->themes->Cms_themes() . '/message/empty_error', $data);
    }
}

/**
 * 
 * @param type $lable
 * @param type $url
 * @param type $mini
 * @param type $icon
 * @param type $theme
 * @param type $inline
 * @param type $tranistion
 * @param type $extra
 * @param type $base_url
 * @return type
 */
function mobile_button($lable = '', $url = '', $mini = 'false', $icon = '', $theme = 'b', $inline = 'true', $tranistion = 'flow', $extra = '', $base_url = true) {
global $CI;
    if ($base_url == true) {
        $url = base_url() . $url;
    } else {
        $url = $url;
    }
    return '<a href="' . $url . '" data-transition="' . $tranistion . '" data-role="button" data-iconpos="right" data-mini="' . $mini . '" data-inline="' . $inline . '" data-icon="' . $icon . '" data-theme="' . $theme . '" ' . $extra . ' />' . $lable . '</a>';
}

/**
 * 
 * @param type $url
 * @return type
 */
function mobile_display_button_edit($url = '', $stues='', $extra = 'data-iconpos="notext"') {
    global $CI;
    // display edit order button where states = 2 : بأنتظار مراجعةالعميل
    if (in_array($stues, array(2, ''))) {
        return mobile_button($CI->lang->line('label_edit'), $url, 'true', 'edit', 'b', 'true', 'flow', $extra);
    }
}

/**
 * 
 * @param type $url
 * @return type
 */
function mobile_display_button_check($url = '', $stues='', $extra = 'data-iconpos="notext"') {
    global $CI;
    // display edit order button where states = 2 : بأنتظار مراجعةالعميل
    if (in_array($stues, array(4,2,3))) {
        return mobile_button($CI->lang->line('label_check'), $url, 'true', 'edit', 'b', 'true', 'flow', $extra);
    }
}

function mobile_display_button_delete($url = '', $stues='', $base_url = false, $extra = 'data-iconpos="notext" data-rel="popup" ') {
    global $CI;
    if (in_array($stues, array(1, 2, 3, ''))) {
        return mobile_button($CI->lang->line('label_delete'), $url, 'true', 'delete', 'e', 'true', 'flow', $extra, $base_url);
    }
}

/**
 * 
 * @global type $CI
 * @return boolean
 */
function if_login() {
    global $CI;
    $login = $CI->session->userdata('logged_in');
    if (empty($login)) {
        return false;
    } elseif ($login == 1) {
        return true;
    }
}



function display_invoice_button($invoice_type = 0, $invoice_id, $url = array(1 => 'orders/add_invoices/', 2 => 'bill/view/')) {
    global  $CI;
    // if invoice_type = 0  no isplay eny thing
    // if invoice_type = 1  no display add invoices
    // if invoice_type = 2  no display view invoices
    if ($invoice_type == 1) {

        return mobile_button($CI->lang->line('label_pay_the_bill'), $url[1] . $invoice_id, $mini = 'true', $icon = 'puls', 'b', '', '', 'data-iconpos="right"');
    } elseif ($invoice_type == 2) {
        $label_button=$CI->lang->line('label_bill_preview_bill');
        return mobile_button($label_button, $url[2] . $invoice_id, $mini = 'true', $icon = 'puls', 'b', '', '', 'data-iconpos="right"');
    }
}

?>
